package com.lb.sql;

public class Condition {

    private String name;// 条件名
    private Opt Operation;// 运算符
    private Object value;// 条件值

    public Condition() {
        super();
    }

    public Condition(Opt operation, String name, Object value) {
        super();
        Operation = operation;
        this.name = name;
        this.setValue(value);
    }

    public static Condition eq(String propertyName, Object value) {
        return new Condition(Opt.Equal, propertyName, value);
    }
    public static Condition unequal(String propertyName, Object value) {
        return new Condition(Opt.UnEqual, propertyName, value);
    }
    public static Condition greatThan(String propertyName, Object value) {
        return new Condition(Opt.GreatThan, propertyName, value);
    }
    public static Condition lessThan(String propertyName, Object value) {
        return new Condition(Opt.LessThan, propertyName, value);
    }
    public static Condition like(String propertyName, Object value) {
        return new Condition(Opt.Like, propertyName, value);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Opt getOperation() {
        return Operation;
    }

    public void setOperation(Opt operation) {
        Operation = operation;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        if (this.Operation != null && this.Operation.equals(Opt.Like)) {
            this.value = "%" + value + "%";
        } else {
            this.value = value;
        }
    }
}
